<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2022/5/25
 * Time: 上午10:42
 */

namespace app\api\controller\v32;

use app\api\controller\v13\Auth2;
use app\common\cachemodel\GoddessBaseInfo;
use app\common\model\Article as ArticleModel;

/**
 * @version v2.8.5
 * Class Article
 * @package app\api\controller\v32
 */
class Article extends Auth2
{
    /**
     * @title 获取文章列表
     * @method GET
     */
    public function index()
    {
        $page = input('page/d', 1);
        $map = [
            'page' => $page,
            'cid' => input('get.cid/d', 0),
            'uid' => $this->user['id'] ?? null,
            'uc_id' => $this->user['uc_id'],
        ];
        if ($map['cid'] < 1 || $map['page'] < 1)
        {
            return show(config('code.error'), '服务异常，请稍后再试');
        }

        $data = (new ArticleModel())->getArticleList($map, 3);
        return show(config('code.success'), '加载成功', $data);
    }

    /**
     * @title 获取文章列表
     * @method GET
     */
    public function index_article()
    {
        //判断是否有公告
        $goddessInfo = (new GoddessBaseInfo())->getInfo(['notice_img3', 'target3', 'link3']);
        $pageData = (new \app\common\cachemodel\Article())->getArticleIndexIds($this->user['id'], 2, 1, 20);
        $article = $pageData['data'];
        if ($goddessInfo['notice_img3'])
        {
            $goddessNotice = [
                'type' => 5,
                'thumb' => $goddessInfo['notice_img3'] ?? '',
                'target' => $goddessInfo['target3'] ?? '',
                'link' => $goddessInfo['link3'] ?? '',
            ];
            array_unshift($article, $goddessNotice);
        }

        return show(config('code.success'), '加载成功', $article);
    }
}
